<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>开始游戏</title>

    <!-- Bootstrap -->
    <link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->


    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

    <script type="text/javascript">

        var id = location.search.substr(4);

        $.ajax({
            type: "GET",
            url: "../api/game/combathouse/selectAll?random=" + Math.random(),
            dataType: "json",
            success: function (msg) {
                //alert(msg.code);
                $.each(msg.data, function (index, item) {
                    var hid=item.roomId;
                    var users=item.users;
                    var nodeString='<li onclick="joinRoom(\''+hid+'\',\'startgame.html?id='+id+'&hid='+hid+'\')"><label>'+hid+'|'+users+'</label></li>';
                    $("#ul").append(nodeString);
                })
                var totalonline = msg.data;
                $("#totalonline").text(totalonline);
            }
        });

        function joinRoom(hid,url) {
            $.ajax({
                type: "POST",
                contentType:"application/json",
                url: "../api/game/combathouse/update",
                data: '{"userId":"'+id+'","roomId":"'+hid+'","opt":"1"}',
                success: function (msg) {
                    //alert(msg.code);;
					if(msg.code===0){
						window.location.href = url;
					}else{
						alert(msg.message);
					}
                }
            });

        }

        function renji() {
            window.location.href = 'startgame2.html?id='+id;
        }

    </script>
</head>
<body>
<div class="jumbotron text-center">
    <h1>石头剪刀布，人机争霸战!</h1>
    <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
        选择房间
    </button>
    <button class="btn btn-primary btn-lg" onclick="renji()">
        人机对战
    </button>
    <p></p>
    <img id="img1" src="./img/initgame.png" class="img-circle">
</div>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    房间列表
                </h4>
            </div>
            <div class="modal-body">
                <button type="button" class="btn btn-default dropdown-toggle"
                        data-toggle="dropdown">
                    请选择 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu" id="ul">
                    <!--<li><a href="startgame.html?hid=1">功能</a></li>
                    <li><a href="startgame.html?hid=1">另一个功能</a></li>
                    <li><a href="startgame.html?hid=1">其他</a></li>-->
                </ul>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

</body>
</html>